<script lang="ts" setup>
import PageTable from "@/components/PageTable/index.vue";
import SearchHeader from "@/components/SearchHeader/index.vue";
import PageContainer from "@/components/PageContainer/index.vue";
import {reactive, ref} from "vue";
import {View, StarFilled} from '@element-plus/icons-vue'
import EleOrderDetail from "@/views/maintenance/components/EleOrderDetail.vue";
import {ButtonColor} from "@/utils/buttonsColor";
import { message } from "@/utils/message";
import {ownerEleOrderList, ownerTargetEleOrderList} from "@/api/demoApi";

defineOptions({
  name: "orderTarget"
});

/**-------------------搜索-------------------**/
//查询参数
const queryList = [
  {key:'projectNo',label:'电表号',type:'input'},
  {key:'projectName',label:'所属站点',type:'input'},
]
//分页
const pageQuery = reactive({
  page:1,
  size:15
})
//查询回调
const searchHandler = (queryForm)=>{
  console.log(queryForm)
}
//分页回调
const paginationHandler = (pageInfo) =>{
  pageQuery.page = pageInfo.page
  pageQuery.size = pageInfo.size
}

/**-------------------列表-------------------**/
//总条数
const total = ref(0)
//表格列
const tableColumns = [
  {label:'电表号',key:'meterNo'},
  {label:'所属站点',key:'stationName'},
  {label:'所属项目',key:'projectName'},
  {label:'业主',key:'ownerName'},
  {label:'付款单位',key:'paymentName'},
  {label:'本次结算度数',key:'payDegree'},
  {label:'电费单价',key:'eleUnit'},
  {label:'应付总额',key:'eleTotal'},
  {label:'实际单价',key:'realUnit'},
  {label:'实付总额',key:'realTotal'},
  {label:'是否非标',key:'isTarget'},
  {label:'非标单价',key:'targetUnit'},
  {label:'非标总额',key:'targetTotal'},
  {label:'创建日期',key:'createTime'},
  {label:'订单状态',key:'status',custom:true},
  {label:'操作',key:'operation',custom:true,width: 300}
]
//表格行数据
const tableData = ref([])
const getTableData = ()=>{
  tableData.value = ownerTargetEleOrderList()
}
getTableData()

/**-------------------操作-------------------**/
//弹窗
const eleOrderDetail = ref()
const openDialog = (type:string,row:object)=>{
  switch (type){
    case 'view':
      eleOrderDetail.value.dialogShow('订单详情',row)
      break
  }
}
//未完成提示
const notDone = ()=>{
  message('抱歉，功能设计中...',{type:'warning'})
}
</script>

<template>
  <PageContainer>
    <!--顶部筛选-->
    <SearchHeader :query-list="queryList" @search="searchHandler" />
    <!--    表格-->
    <PageTable :columns="tableColumns" :page="pageQuery.page" :size="pageQuery.size" :table-data="tableData" :total="total" @pagination="paginationHandler">
      <template #status="{row}">
        <el-tag v-if="row.status===0" type="info">待确认</el-tag>
        <el-tag v-if="row.status===1" type="info">待非标确认</el-tag>
        <el-tag v-if="row.status===2" type="primary">待发起审批</el-tag>
        <el-tag v-if="row.status===3" type="success">已支付</el-tag>
        <el-tag v-if="row.status===4" type="warning">审批驳回</el-tag>
        <el-tag v-if="row.status===5" type="warning">审批撤回</el-tag>
        <el-tag v-if="row.status===6" type="danger">已作废</el-tag>
      </template>
      <template #operation="{row}">
        <el-button :color="ButtonColor.VIEW" :icon="View" plain round size="small" @click="openDialog('view',row)">详情</el-button>
        <el-button v-if="row.status === 1" :icon="StarFilled" plain round size="small" type="danger" @click="notDone">非标确认</el-button>
      </template>
    </PageTable>

    <!--  弹窗-->
    <EleOrderDetail ref="eleOrderDetail" />
  </PageContainer>
</template>

<style lang="scss" scoped>

</style>
